﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">客户姓名</label>
            <div class="layui-input-block">
                <input type="text" name="customerName" lay-verify="required" lay-reqtext="标题不能为空" placeholder="请输入标题" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">客户手机</label>
            <div class="layui-input-block">
                <input type="text" name="customerPhone" lay-verify="required" lay-reqtext="单位不能为空" placeholder="请输入单位" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">客户地址</label>
            <div class="layui-input-block">
                <input type="text" name="customerAddress" placeholder="请输入价格" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ">房子面积</label>
            <div class="layui-input-block">
                <input type="number" name="area" placeholder="请输入主要成本" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ">代理人</label>
            <div class="layui-input-block">
                <input type="text" name="agentName" placeholder="请输入辅料成本" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ">代理人电话</label>
            <div class="layui-input-block">
                <input type="text" name="agentPhone" placeholder="请输入机械成本" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ">开工时间</label>
            <div class="layui-input-block">
                <input type="text" name="startTime" class="layui-input" id="startTime" placeholder="请选择开始时间">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ">竣工时间</label>
            <div class="layui-input-block">
                <input type="text" name="endTime" class="layui-input" id="endTime" placeholder="请选择竣工时间">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设计师</label>
            <div class="layui-input-block">
                <select name="designerId" lay-filter="designer" id="designerSelect">
                    <option value=""></option>
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;
            var laydate = layui.laydate;

            // 渲染开工时间选择框
            laydate.render({
                elem: '#startTime'
            });
            // 渲染竣工时间选择框
            laydate.render({
                elem: '#endTime'
            });

            //发起异步请求获取部门下拉选的备选数据
            $.ajax({
                url: '/UserInfo/GetSelectOptionList',
                type: 'get',
                data: {},
                success: function (res) {
                    if (res.code == 200) {
                        //遍历数组，添加备选数据到下拉选中
                        var list = res.data;
                        for (var i = 0; i < list.length; i++) {
                            $('#designerSelect').append('<option value="' + list[i].id + '">' + list[i].userName + '</option>');
                        }
                        form.render('select');
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                $.ajax({
                    url: '/Order/CreateOrder',
                    type: 'post',
                    data: data.field,
                    success: function (res) {
                        if (res.code == 200) {
                            //关闭添加页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);

                            //执行搜索重载
                            window.parent.table.reload('currentTableId', {
                                page: {
                                    curr: 1
                                }
                                , where: {
                                }
                            }, 'data');

                        } else {
                            layer.msg(res.msg);
                        }
                    }
                });

                // var index = layer.alert(JSON.stringify(data.field), {
                //     title: '最终的提交信息'
                // }, function () {




                //     // 关闭弹出层
                //     layer.close(index);

                //     var iframeIndex = parent.layer.getFrameIndex(window.name);
                //     parent.layer.close(iframeIndex);

                // });

                return false;
            });

        });
    </script>
</body>
</html>